<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box {
        border: 1px solid gray;
        width: 180px;
        height: 250px;
        text-align: center;

    }

    .box img {
        margin: auto;
        width: 120px;
        height: 120px;
    }

    .sonBox {
        padding: 0px 5px;
        display: flex;
        justify-content: space-between;
    }

    p {
        padding: 0px 5px;

        text-align: left;
    }

    .span1 {
        color: red;
        font-size: 17px;
    }
    .sonBox1 {
        border: 1px solid red;
        color: red;
        border-radius: 10px;
        padding: 0 3px;
        font-size: 10px;

    }

    .sonBox2 {
        font-size: 10px;
        padding: 0 3px;

        border: 1px solid gray;
        color: gray;
        border-radius: 10px;
    }

    .content {
        display: flex;
    }
</style>

<body>
    <div id="app">
        <h2>当前点击的是：{{msg}}</h2>
        <div class="content">
            <div class="" v-for="item in list" :key="item.id">
                <my-cpn :listdata="item" @changeid="changeIdData"></my-cpn>
            </div>
        </div>


    </div>
    <script src="../js/vue.js"></script>
    <template id="myCpn">

        <div class="box" @click="clickCpn">
            <div>
                <img :src="listdata.addr" alt="">

            </div>
            <div>
                <p>{{listdata.p1}}</p>

            </div>
            <div class="sonBox">
                <div>
                    <span class="span1">{{listdata.span1}}</span>

                </div>

                <div class="sonBox1">{{listdata.boxfont1}}</div>
                <div class="sonBox2">{{listdata.boxfont2}}</div>

            </div>
        </div>

    </template>

    <script>
        const app = new Vue({
            el: '#app',
            data() {
                return {
                    list: [{
                            id: 1,
                            addr: "./img/7f5fab059643521e41406131379c7b4a.jpg",
                            p1: "小米11 Ultra，开启影像新时代",
                            span1: "￥5999起",

                            boxfont1: "上新",
                            boxfont2: "看相似",
                        },
                        {
                            id: 2,
                            addr: "./img/QQ图片20220323171305.png",
                            p1: "小米11 Ultra，开启影像新时代",
                            span1: "￥5999起",
                            boxfont1: "上新",
                            boxfont2: "看相似",
                        },
                        {
                            id: 3,
                            addr: "./img/QQ图片20220323171309.png",
                            p1: "小米11 Ultra，开启影像新时代",
                            span1: "￥5999起",
                            boxfont1: "上新",
                            boxfont2: "看相似",
                        },
                        {
                            id: 4,
                            addr: "./img/QQ图片20220323171329.png",
                            p1: "小米11 Ultra，开启影像新时代",
                            span1: "￥5999起",
                            boxfont1: "上新",
                            boxfont2: "看相似",
                        },

                    ],
                    msg: null,
                }
            },
            components: {
                'my-cpn': {
                    template: '#myCpn',
                    props: ['listdata'],
                    methods: {
                        clickCpn() {
                            this.$emit('changeid', this.listdata.id)
                        }
                    },
                    data() {
                        return {

                        }
                    },

                }
            },
            methods: {
                changeIdData(val) {
                    if (val == 1) {
                        this.msg = '第一个'
                    } else if (val == 2) {
                        this.msg = '第二个'
                    } else if (val == 3) {
                        this.msg = '第三个'
                    } else if (val == 4) {
                        this.msg = '第四个'
                    }
                }
            }

        })
    </script>
</body>

</html>